// src/renderer/utils/webSocket.ts
import { onMounted, onBeforeUnmount } from "vue";
import { connect, closeConnection, isConnected } from "./webSocketManager"; // 导入 WebSocket 管理器

const useWebSocket = () => {
    // 组件挂载时执行
    onMounted(() => {
        connect(); // 尝试建立连接
    });

    // 组件卸载前执行
    onBeforeUnmount(() => {
        closeConnection(); // 关闭 WebSocket 连接
    });

    return {
        isConnected,
    };
};

export default useWebSocket;